# Maintainer: Martell Malone <martell malone at g mail dot com >

_realname=libwebsockets
_srcbase=chrome43-firefox-36
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.4
pkgrel=1
arch=('any')
pkgdesc="A lightweight pure C library for websockets (mingw-w64)"
url='http://libwebsockets.org/'
license=('LGPL 2.1 - custom')
depends=("${MINGW_PACKAGE_PREFIX}-zlib" "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://github.com/warmcat/${_realname}/archive/v${pkgver}-${_srcbase}.tar.gz"
        #http://git.libwebsockets.org/cgi-bin/cgit/${_realname}/snapshot/${_realname}-${pkgver}-${_srcbase}.tar.gz
        fix-cmake-files-location.patch)
options=(!strip !buildflags staticlibs)
sha256sums=('e11492477e582ef0b1a6ea2f18d81a9619b449170a3a5c43f32a9468461a9798'
            'd96babea5c9f7164fe4f734e7c525106430de15dd6740288ad69520a38bd0698')

prepare() {
  cd ${_realname}-${pkgver}-${_srcbase}
  patch -p1 -i ${srcdir}/fix-cmake-files-location.patch
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DLWS_USE_EXTERNAL_ZLIB=ON \
    -DCMAKE_C_COMPILER=${MINGW_PREFIX}/bin/gcc.exe \
    -DCMAKE_CXX_COMPILER=${MINGW_PREFIX}/bin/g++.exe \
    -DLWS_WITHOUT_DAEMONIZE=ON \
    -DLWS_WITHOUT_TESTAPPS=ON \
    -DCMAKE_BUILD_TYPE=RELEASE \
    ../${_realname}-${pkgver}-${_srcbase}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} -j1 install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}-${_srcbase}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
